package sv.gob.mh.dgii.service;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import sv.gob.mh.dgii.common.PagedResult;

import sv.gob.mh.dgii.dao.hibernate.Dao;

/**
 * Este tipo de servicio es mas que todo para aquellos donde se necesite la
 * funcionalidad de un crud
 *
 * @author hugo
 *
 */
@Transactional
public abstract class BaseService implements Dao {

    public abstract Dao getDao();

    @Override
    public void save(Object obj) {
        getDao().save(obj);
    }

    @Override
    public void saveOrUpdate(Object obj) {
        getDao().saveOrUpdate(obj);
    }

    @Override
    public void update(Object obj) {
        Object old = getDao().findByKey(obj);
        getDao().update(old);
    }

    @Override
    public List find(Object example) {
        return getDao().find(example);
    }

    @Override
    public void remove(Object obj) {
        getDao().remove(obj);
    }

    @Override
    public Object findByKey(Object obj) {
        return getDao().findByKey(obj);
    }

    @Override
    public Object findById(Serializable id) {
        return getDao().findById(id);
    }

    @Override
    public Object findById(Class c, Serializable id) {
        return getDao().findById(c, id);
    }

    @Override
    public List findAll() {
        return getDao().findAll();
    }

    @Override
    public List getAll() {
        return getDao().getAll();
    }

    @Override
    public List getPage(int page, int pageSize, String sortProperty, String sortDirection) {
        return getDao().getPage(page, pageSize, sortProperty, sortDirection);
    }

    @Override
    public PagedResult getPagedResult(int page, int pageSize, String sortProperty, String sortDirection) {
        return getDao().getPagedResult(page, pageSize, sortProperty, sortDirection);
    }

    @Override
    public PagedResult getPage(int page, int pageSize, String sortProperty, String sortDirection, List criterions) {
        return getDao().getPage(page, pageSize, sortProperty, sortDirection, criterions);
    }

    @Override
    public PagedResult getPage(int page, int pageSize, String sortProperty, String sortDirection, Object sample) {
        return getDao().getPage(page, pageSize, sortProperty, sortDirection, sample);
    }

    @Override
    public Number getAllCount() {
        return getDao().getAllCount();
    }

    @Override
    public List getByExample(Object xample) {
        return getDao().getByExample(xample);
    }

    @Override
    public void synchronize() {
        getDao().synchronize();
    }

    @Override
    public void merge(Object obj) {
        getDao().merge(obj);
    }

    public Date getDate() {
        return Calendar.getInstance().getTime();
    }
}
